package com.zyh.stream;

import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.List;
import java.util.Random;
import java.util.stream.Stream;

/**
 * @Author zyh
 * @Date 2024/8/16 9:37
 * @Description Stream流
 */

public class StreamDemo1 {
    @Test
    public void test2(){
        Stream<Integer> stream1 = Stream.of(1, 2, 3, 4, 5);
        stream1.forEach(System.out::println);
        System.out.println("----------------------");
        Stream<Integer> stream2 = Stream.iterate(10, item -> item + 3).limit(5);
        stream2.forEach(System.out::println);
        System.out.println("------------------");
        Stream<Integer> stream3 = Stream.generate(() -> new Random().nextInt(10)).limit(10);
        stream3.forEach(System.out::println);

    }
    @Test
    public void test1(){
        List<Integer> list = Arrays.asList(1, 2, 3, 4, 5, 6);
        //创建单行流对象
        Stream<Integer> stream1 = list.stream();
        stream1.forEach(System.out::println);
        System.out.println("-----------");
        //创建并行流对象
        Stream<Integer> stream2 = list.parallelStream();
        stream2.forEach(System.out::println);
        System.out.println("----------------");
        //创建数组
        String[] strArr={"java","C++","python","html5","php","Vue"};
        //使用数组工具类创建流
        Stream<String> stream3 = Arrays.stream(strArr);
        stream3.forEach(item->{
            if (item.length()>=5){
                System.out.println(item);
            }
        });
//        stream3.forEach(System.out::println);
    }
}
